package com.b2c.pojo.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import content.common.DateFormat;
import content.enumeration.LoginStatus;
import lombok.Builder;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import validGroup.InsertGroup;
import validGroup.UpdateGroup;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.time.LocalDateTime;

import static content.common.ValidMessage.INSERT_ID;
import static content.common.ValidMessage.UPDATE_ID;

/**
 * @TableName mall_admin_user
 */
@TableName(value = "mall_admin_user")
@Data
@Builder
public class AdminUser implements Serializable {
    /**
     *
     */
    @TableId(value = "id",type = IdType.AUTO)
    @Null(message = INSERT_ID,groups = {InsertGroup.class})
    @NotNull(message = UPDATE_ID,groups = {UpdateGroup.class})
    private Integer id;

    /**
     *
     */
    @TableField(value = "username")
    private String username;
    /**
     * 别名
     */
    @TableField(value = "nick_name")
    private String nickName;

    /**
     *
     */
    @TableField(value = "password")
    private String password;
    /**
     * 用户头像
     */
    @TableField(value = "image")
    private String image;

    /**
     *
     */
    @TableField(value = "phone")
    private String phone;

    /**
     *
     */
    @TableField(value = "sex")
    private String sex;
    @TableField(value = "email")
    private String email;
    @TableField(value = "status")
    private LoginStatus status;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = DateFormat.FORMAT_PATTERN_SECODE)
    @JsonFormat(pattern = DateFormat.FORMAT_PATTERN_SECODE)
    private LocalDateTime createTime;
    @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH-mm-ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss")
    private LocalDateTime updateTime;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        AdminUser other = (AdminUser) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
                && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
                && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone()))
                && (this.getSex() == null ? other.getSex() == null : this.getSex().equals(other.getSex()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
        result = prime * result + ((getSex() == null) ? 0 : getSex().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", username=").append(username);
        sb.append(", password=").append(password);
        sb.append(", phone=").append(phone);
        sb.append(", sex=").append(sex);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}